﻿/*
 * Copyright (c) 2010, Sergey Loktin (mailto://shadowconsp@gmail.com)
 * Licensed under The MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MoonyDesk
{
    /// <summary>
    /// Interaction logic for PluginSettingsCtrl.xaml
    /// Control for plugin settings tab
    /// </summary>
    public partial class PluginSettingsCtrl : UserControl
    {
        private DesktopWindow _mainWindow;
        private LoadedPlugin _plugin;

        public PluginSettingsCtrl(LoadedPlugin Plugin)
        {
            InitializeComponent();
            _plugin = Plugin;
            if (_plugin.Active)
            {
                _mainWindow = _plugin.MainWindow;
                this.DataContext = _mainWindow;
                SizeTab.DataContext = _mainWindow.viewBox;
                RotateTab.DataContext = _mainWindow.rotate;
                List<MoonyPlugin.SettingsTab> tabs = Plugin.GetNewSettingsTabs();
                if (tabs != null)
                {
                    foreach (MoonyPlugin.SettingsTab tab in tabs)
                    {
                        PluginSettingsTab pluginSettingsTab = new PluginSettingsTab();
                        pluginSettingsTab.Text = tab.HeaderText;
                        pluginSettingsTab.ImageSource = tab.HeaderImageSource;
                        pluginSettingsTab.Content = tab.Content;
                        TabControl.Items.Add(pluginSettingsTab);
                    }
                }
            }
            else
            {
                this.Visibility = Visibility.Hidden;
            }
        }

        private void MoveUp_Click(object sender, RoutedEventArgs e)
        {
            _mainWindow.Top--;
            if (_mainWindow.Top < -_mainWindow.ActualHeight)
                _mainWindow.Top = -_mainWindow.ActualHeight;
        }

        private void MoveDown_Click(object sender, RoutedEventArgs e)
        {
            _mainWindow.Top++;
            if (_mainWindow.Top > System.Windows.SystemParameters.PrimaryScreenHeight)
                _mainWindow.Top = System.Windows.SystemParameters.PrimaryScreenHeight;
        }

        private void MoveLeft_Click(object sender, RoutedEventArgs e)
        {
            _mainWindow.Left--;
            if (_mainWindow.Left < -_mainWindow.ActualWidth)
                _mainWindow.Left = -_mainWindow.ActualWidth;
        }

        private void MoveRight_Click(object sender, RoutedEventArgs e)
        {
            _mainWindow.Left++;
            if (_mainWindow.Left > System.Windows.SystemParameters.PrimaryScreenWidth)
                _mainWindow.Left = System.Windows.SystemParameters.PrimaryScreenWidth;
        }
    }
}
